//统一管理咱们项目用户相关的接口
import request from "@/utils/request";
import type {HandleResponseData, UuidsForm} from "../../common/type";
import {
    DictAddOrUpdateForm,
    DictInfoResponseData,
    DictListResponseData
} from "@/api/sys/dict/type";

//项目用户相关的请求地址
enum API {
    //分页列表
    pageListDictUrl = "/bg/dict/pageList",
    //详情
    infoDictUrl = "/bg/dict/detail",
    //编辑
    updateDictUrl = "/bg/dict/update",
    //添加
    addDictUrl = "/bg/dict/add",
    //删除
    delDictUrl = "/bg/dict/batchDel"
}

//顶级分页列表
export const reqTopDictPageList = (page: number, pageSize: number,dictNameLike:string,dictCodeLike:string) =>
    request.get<any, DictListResponseData>(API.pageListDictUrl +`?page=${page}&pageSize=${pageSize}&dictNameLike=${dictNameLike}
&dictCodeLike=${dictCodeLike}&top=1`)



//子级分页列表
export const reqDictPageList = (page: number, pageSize: number,dictNameLike:string,dictCodeLike:string,dictParentCode:string) =>
    request.get<any, DictListResponseData>(API.pageListDictUrl +`?page=${page}&pageSize=${pageSize}&dictNameLike=${dictNameLike}
&dictCodeLike=${dictCodeLike}&top=0&dictParentCode=${dictParentCode}`)




//详情
export const reqDictInfo = (uuid: string) => request.get<any, DictInfoResponseData>(API.infoDictUrl + `?uuid=` + `${uuid}`);

//添加/编辑
export const reqAddOrUpdateDict = (data: DictAddOrUpdateForm) => {
    if (data.uuid) {
        return request.post<any, HandleResponseData>(API.updateDictUrl, data);
    } else {
        return request.post<any, HandleResponseData>(API.addDictUrl, data);
    }
}

//批量删除
export const reqBatchDelDict = (uuidsForm: UuidsForm) => request.post<any, HandleResponseData>(API.delDictUrl, uuidsForm)
